package com.example.music_mediaplayer.tool;

import java.util.Formatter;
import java.util.Locale;

/**
 * Created by quan on 2018/1/15.
 */

public class MsToTimeUtils {
    private static StringBuilder mFormatBuilder =  new StringBuilder();
    private static Formatter mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());

    /**
     * 把毫秒转换成：1：20：30这样的形式
     * @param timeMs
     * @return
     */
    public static String stringForTime(int timeMs){
        int totalSeconds = timeMs/1000;
        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds/60)%60;
        int hours = totalSeconds/3600;
        mFormatBuilder.setLength(0);
        if(hours>0){
            return mFormatter.format("%d:%02d:%02d",hours,minutes,seconds).toString();
        } else {
            return mFormatter.format("%02d:%02d",minutes,seconds).toString();
        }
    }
}
